#pragma once
#include <cstring>
#include <iostream>
#include <mosquitto.h>
#include <string>

class BaseMQTTClient {
public:
  BaseMQTTClient(const char *client_id, const char *host = "localhost",
                 int port = 1883, int keep_alive = 60);

  virtual ~BaseMQTTClient();

  bool connect();
  void disconnect();
  void loop_start();
  void loop_stop();

protected:
  struct mosquitto *mosq;
  std::string broker_host;
  int broker_port;
  int keep_alive;

  // 自动重连回调
  static void on_disconnect(struct mosquitto *mosq, void *obj, int rc);
};
